﻿Imports FSUIPC
Module Fuel_Used
#Region "FSUIPC Fuel Addresses"
    ' Left Tanks.
    Dim Fuel_Left_Tip_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &HB8C)
    Dim Fuel_Left_Aux_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &HB84)
    Dim Fuel_Left_Main_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &HB7C)

    ' Right Tanks.
    Dim Fuel_Right_Tip_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &HBA4)
    Dim Fuel_right_Aux_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &HB9C)
    Dim Fuel_Right_Main_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &HB94)

    ' Center Tanks.
    Dim Fuel_Center1_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &HB74)
    Dim Fuel_Center2_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4b", &H1244)
    Dim Fuel_Center3_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &H124C)

    ' Externals.
    Dim Fuel_Ext1_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &H1254)
    Dim Fuel_Ext2_Percent As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)("Screen4", &H125C)
#End Region

#Region "Screen 4 - Fuel Usage."
    Public Sub Display_Screen()
        Dim img As New System.Drawing.Bitmap(160, 43)
        Dim screen As Drawing.Graphics = Graphics.FromImage(img)
        Try
            FSUIPC.FSUIPCConnection.Process("Screen4")

            ' Format Percentages.
            ' Left Tanks.
            Dim Fuel_Left_Tip_Percent_Calc As Double = (Fuel_Left_Tip_Percent.Value / (128 * 65536))
            Dim Fuel_Left_Aux_Percent_Calc As Double = (Fuel_Left_Aux_Percent.Value / (128 * 65536))
            Dim Fuel_Left_Main_Percent_Calc As Double = (Fuel_Left_Main_Percent.Value / (128 * 65536))
            ' Right Tanks.
            Dim Fuel_Right_Tip_Percent_Calc As Double = (Fuel_Right_Tip_Percent.Value / (128 * 65536))
            Dim Fuel_Right_Aux_Percent_Calc As Double = (Fuel_right_Aux_Percent.Value / (128 * 65536))
            Dim Fuel_Right_Main_Percent_Calc As Double = (Fuel_Right_Main_Percent.Value / (128 * 65536))
            ' Center Tanks.
            Dim Fuel_Center1_Percent_Calc As Double = (Fuel_Center1_Percent.Value / (128 * 65536))
            Dim Fuel_Center2_Percent_Calc As Double = (Fuel_Center2_Percent.Value / (128 * 65536))
            Dim Fuel_Center3_Percent_Calc As Double = (Fuel_Center3_Percent.Value / (128 * 65536))
            ' External Tanks.
            Dim Fuel_Ext1_Percent_Calc As Double = (Fuel_Ext1_Percent.Value / (128 * 65536))
            Dim Fuel_Ext2_Percent_Calc As Double = (Fuel_Ext2_Percent.Value / (128 * 65536))


            screen.DrawLine(Pens.White, 0, 0, 159, 0)
            screen.DrawLine(Pens.White, 0, 37, 159, 37)
            screen.DrawLine(Pens.White, 79, 0, 79, 37)
            screen.DrawLine(Pens.White, 0, 0, 0, 37)
            screen.DrawLine(Pens.White, 159, 0, 159, 37)

            ' Display Data.

        Catch exFSUIPC As FSUIPCException
            MainTimer.Stop()
            CheckTimer.Start()
        Finally
            G15FS9_Main.lcd.DrawLCD(img)
            G15FS9_Main.lcd.UpdateLCD()
        End Try
    End Sub
#End Region
End Module
